import java.awt.*;
import java.util.Random;
import java.util.Scanner;

public class NGuessNumber {
    /**
     * 随机生成4个0-9之间不重复的整数作为答案
     */
    public static int [] generateAnswer(){
        Random random = new Random();
        int randomAllNumber[] = new int[4];
        int a =0;
        while(a ==0){
        for (int i = 0; i < 4; i++) {
            int randomNumber = random.nextInt(10);
            randomAllNumber[i]=randomNumber;
        }
        for (int i = 0; i < 4; i++) {
            for (int j = 3; j >i ; j--) {
                if (randomAllNumber[i]==randomAllNumber[j]){
                    a=0;
                    break;
                }else{
                    a=1;
                }
            }
            if (a==0) break;
            }
        }
        return randomAllNumber;
    }

    /**
     *获取玩家输入的4个数字
     */
    public static int[] getPlayerInput(){
        Scanner scanner = new Scanner(System.in);

        int playerNumber[] = new int[4];
        for (int i = 0; i < 4; i++) {
             playerNumber[i]=scanner.nextInt();
        }
        return playerNumber;
    }

    /**
     * 比较玩家猜测后返回信息
     */
    public static List compareGuessAnswer(int c[],int g[]){
        List end=new List();
        int a=0;
        int b=0;
        for (int i = 0; i < c.length; i++) {
            for (int j = 0; j < g.length; j++) {
                if (c[i]==g[j]){
                    if (i==j) a++;
                    else if (i!=j)b++;
                }
            }
        }
        end.add(Integer.toString(a),0);
        end.add(Integer.toString(b),1);
        return end;
    }

    /**
     * 判断游戏是否胜利
     */
    public static boolean iswin(String a){
        if (Integer.parseInt(a)==4){
            return true;
        }
        return false;
    }

    public static void main(String[] args) {

        boolean star=true;
        while (star){
        Scanner scanner = new Scanner(System.in);
       int gameNum[]= generateAnswer();
       System.out.println("!!新的猜数字小游戏开始了!!");
       boolean b =false;
       while(!b){
       int playerNum[] =getPlayerInput();
       List end =compareGuessAnswer(gameNum,playerNum);
       b=iswin(end.getItem(0));
       if (!b){
           System.out.println(end.getItem(0)+ " A "+end.getItem(1)+" B");
       }else {
           System.out.println("!!恭喜恭喜！！");
       }
       }
        System.out.println("！！Y继续游戏！！");
        System.out.println("！！N退出游戏！！");
        while (true){
            String userChoose = scanner.next();
            if (userChoose.equals("Y")||userChoose.equals("y")){
                break;
            }else if(userChoose.equals("N")||userChoose.equals("n")){
                star = false;
                break;
            }else
                System.out.println("!!输入的不对，你还玩不玩!!");
        }
    }
    }
}
